package com.example.springioc.entity;

import com.example.springioc.controller.UserController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan({"com.example.springioc"})
@SpringBootApplication
public class SpringIocApplication {

    public static void main(String[] args) {
//        获取Spring上下文对象
        ConfigurableApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);
////        从Spring上下文中对象中获取特定的对象
//        UserController userController = context.getBean(UserController.class);
////        使用获取到的特定的对象的方法
//        userController.sayHi();
//
////        根据bean类型, 从Spring上下文中对象中获取特定的对象
//        UserController userController1 = context.getBean(UserController.class);
////        根据bean类型名称, 从Spring上下文中对象中获取特定的对象
//        UserController userController2 = (UserController) context.getBean("userController");
////        根据bean类型 + 名称, 从Spring上下文中对象中获取特定的对象
//        UserController userController3 = context.getBean("userController", UserController.class);
//
//        System.out.println(userController1);
//        System.out.println(userController2);
//        System.out.println(userController3);
//
////        User user = context.getBean(User.class);
////        System.out.println(user);
//
////        参数严格和函数名匹配
////        User user1 = (User)context.getBean("user1");
////        User user2 = (User)context.getBean("User2");
////        System.out.println(user1);
////        System.out.println(user2);
//
//        User user1 = (User)context.getBean("u1");
//        User user2 = (User)context.getBean("u2");
//        System.out.println(user1);
//        System.out.println(user2);

        UserController userController = context.getBean("userController", UserController.class);
        userController.sayHi();
    }
}
